﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Zyg.SSO.Web.Admin.Settings
{
    public partial class Setting : Zyg.SSO.Web.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (!base.Account.HavePermission(Zyg.SSO.Core.Business.Permission.SettingManage))
                {
                    throw new Exception("你无权查看此页面");
                }
                Bind();
            }
        }

        void Bind()
        {
            Zyg.SSO.Core.Business.SysSetting settings = Zyg.SSO.Core.Business.SysSetting.GetCurrent();

            if (settings.RegisterCheck)
            {
                SettingRegisterCheck.SelectedIndex = 0;
            }
            else
            {
                SettingRegisterCheck.SelectedIndex = 1;
            }

            SettingRegisterCopyright.Text = settings.Copyright;
            SettingRegisterPageSize.Text = settings.PageSize.ToString();
        }

        protected void BtnSubmit_Click(object sender, EventArgs e)
        {
            Zyg.SSO.Core.Business.SysSetting settings = new Zyg.SSO.Core.Business.SysSetting();

            settings.Id = Guid.NewGuid();

            if (SettingRegisterCheck.SelectedIndex == 0)
            {
                settings.RegisterCheck = true;
            }
            else
            {
                settings.RegisterCheck = false;
            }

            settings.PageSize = int.Parse(SettingRegisterPageSize.Text);
            settings.Copyright = SettingRegisterCopyright.Text;

            settings.Save();

            WriteBackScript("alert('修改系统设置成功')");
        }
    }
}
